package com.example.park2212.visitor

import androidx.lifecycle.MutableLiveData
import com.example.lib_base.entity.VisitBean
import com.example.lib_base.entity.VisitBeanItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
@HiltViewModel
class VisitorViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {

    val visitSuccess =MutableLiveData<VisitBean>()
    fun visit(){
        httpRequest({
            apiService.visit()
        },{visitSuccess.value =it})
    }

    fun visStatus(status:String){
        httpRequest({
            apiService.visStatus(status)
        },visitSuccess::postValue)
    }

    val visitByIdSuccess = MutableLiveData<VisitBeanItem>()
    fun visitById(id:Int){
        httpRequest({
            apiService.getVisitById(id)
        },visitByIdSuccess::postValue)
    }

    val visitAddSuccess = MutableLiveData<VisitBean>()
    fun visitAdd(bean: VisitBeanItem){
        httpRequest({
            apiService.visitAdd(mapToBody(bean))
        },visitAddSuccess::postValue)
    }

    val approveVisitSuccess = MutableLiveData<VisitBeanItem>()
    fun approveVisit(id:Int){
        httpRequest({
            apiService.approveVisit(id)
        },approveVisitSuccess::postValue)
    }

    val rejectVisitSuccess = MutableLiveData<VisitBeanItem>()
    fun rejectVisit(id:Int){
        httpRequest({
            apiService.rejectVisit(id)
        },rejectVisitSuccess::postValue)
    }

    val deleteVisitSuccess = MutableLiveData<Boolean>()
    fun deleteVisit(id:Int){
        httpRequest({
            apiService.deleteVisit(id)
        },deleteVisitSuccess::postValue)
    }




}